package com.player.thirdGroup.controller;

import com.player.thirdGroup.entity.Menu;
import com.player.thirdGroup.entity.User;
import com.player.thirdGroup.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author VULCAN
 * @create 2019-12-28 7:50
 * @desc 菜单
 **/
@Controller
public class MenuController {
    @Autowired
    private MenuService menuService;

    @RequestMapping("/menulist")
    @ResponseBody
    public List<Menu> menuList(HttpServletRequest request){
        User login = (User) request.getSession().getAttribute("logins");
        return menuService.menuList(login.getUserid());
    }

    //跳转树
    @RequestMapping("/tree")
    public String tree(){

        return "menu";
    }


    @RequestMapping("/lists")
    @ResponseBody
    public List<Menu> lists(Model model){
        List<Menu> lists = menuService.lists();
        model.addAttribute("list", lists);
        System.out.println("ss");
        return lists;
    }
    @RequestMapping("/listmenu")
    @ResponseBody
    public List<Menu> listmenu(Model model){
        List<Menu> lists = menuService.lists();
        System.out.println(lists);
        // model.addAttribute("list", lists);
        return lists;
    }
    //    @RequestMapping("/trees")
//    public String trees(Model model){
//        List<Menu> lists = menuService.lists();
//         model.addAttribute("list", lists);
//        return "trees";
//    }
    @RequestMapping("/trees2")
    public String trees2(Model model){
        List<Menu> lists = menuService.lists();
        model.addAttribute("list", lists);
        return "tree";
    }


}
